<script src="__JS__/jquery.min.js?v=2.1.4"></script>
<script src="__JS__/bootstrap.js?v=3.3.7"></script>
<script src="__JS__/jquery.form.js"></script>
<script src="__JS__/plugins/layui/layui.js"></script>
<script src="__JS__/wk.js"></script>
<script src="__JS__/cropper.min.js"></script>
<script src="__JS__/plugins/viewer/viewer.js"></script>
<script src="__JS__/common.js"></script>
<script src="__JS__/webupload/webuploader.js"></script>
<script src="__JS__/plugins/zTree/jquery.ztree.core-3.5.js"></script>
<script src="__JS__/plugins/zTree/jquery.ztree.excheck-3.5.js"></script>
<!--<script src="__JS__/plugins/zTree/jquery.ztree.exedit-3.5.js"></script>-->
<script src="__JS__/plugins/formSelects-v4/formSelects-v4.js"></script>
<script src="__JS__/plugins/wangEditor-3.1.1/release/wangEditor.js" ></script>
<script src="__JS__/plugins/wx-audio/wx-audio.js" ></script>
<script>

    //图片灯箱
    function imgDisplay(obj) {
        var src = $(obj).attr("src");
        var imgHtml = '<div class="showP"><img src=' + src + ' style="margin-top: 30px;height:90%;margin-bottom: 50px;"  /><p class="closeP"  onclick="closePicture(this)"><span class="cha">×</span></p></div>'
        $('body').append(imgHtml);
    }

    //关闭图片灯箱
    function closePicture(obj) {
        $(obj).parent("div").remove();
    }
    //关闭自动填充
    $('input').attr('autocomplete',"off");

    //layuitable表格重载
    function tableReload(){
        layui.use('table', function () {
            var table = layui.table;
            var keyReload = $('#key');
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    key: keyReload.val()
                }
            });
        });
    }
    var config = {
        '.chosen-select': {},
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }

    //view初始化查看图片
    function view(obj){
        $(obj).viewer({
            url: 'data-original',
        });
    }
</script>

<script>
    //地区三级联动
    function area(obj,type){
        if($(obj).val() == ''){
            if(type == 'province'){
                $("#city").empty();
                $("#city").append('<option value="">---- 所在市 ----</option>');
                $("#city").trigger("chosen:updated");
                $("#district").empty();
                $("#district").append('<option value="">---- 所在区 ----</option>');
                $("#district").trigger("chosen:updated");
            }else if(type == 'city'){
                $("#district").empty();
                $("#district").append('<option value="">---- 所在区 ----</option>');
                $("#district").trigger("chosen:updated");
            }
            return false;
        }
        $.ajax({
            url:"{:url('mec/Base/place')}",
            dataType:"json",
            data:'id='+$(obj).val(),
            type:'post',
            success:function(res){
                var opt = null;
                $.each(res.msg,function(key,vo){
                    opt = opt+"<option value="+vo.district_id+">"+vo.district+"</option>";
                })
                if(type == 'province'){
                    $("#city").empty();
                    $("#city").append('<option value="">---- 所在市 ----</option>');
                    $("#city").append(opt);
                    $("#city").trigger("chosen:updated");
                    $("#district").empty();
                    $("#district").append('<option value="">---- 所在区 ----</option>');
                    $("#district").trigger("chosen:updated");
                }else if(type == 'city'){
                    $("#district").empty();
                    $("#district").append('<option value="">---- 所在区 ----</option>');
                    $("#district").append(opt);
                    $("#district").trigger("chosen:updated");
                }
            }
        })
    }
</script>
<script>
    //tips框
    $('#offAll').on('mouseover', function(){
        var that = this;
        layer.tips('<span style="color:#686B6D;"><i class="fa fa-info-circle"></i> 若未勾选默认禁用全部</span>', that,{tips: [2, '#F2F2F2'],time: 10000});
    });
    //tips框
    $('#onAll').on('mouseover', function(){
        var that = this;
        layer.tips('<span style="color:#686B6D;"><i class="fa fa-info-circle"></i> 若未勾选默认启用全部</span>', that,{tips: [2, '#F2F2F2',''],time: 10000});
    });
    //tips框
    $('#excel').on('mouseover', function(){
        var that = this;
        layer.tips('<span style="color:#686B6D;"><i class="fa fa-info-circle"></i> 导出筛选完成数据</span>', that,{tips: [2, '#F2F2F2',''],time: 10000});
    });
    //关闭tips框
    $('#offAll,#onAll,#export,#excel').on('mouseout', function(){
        layer.closeAll('tips');
    });

    //重置搜索框
    $('#empty').on('click',function(){
        $('.search').val('');
        $(".search").trigger("chosen:updated");
    })

    //layui公共操作
    layui.use('table', function() {
        var form = layui.form
            ,table = layui.table
        //表格排序
        table.on('sort(demo)', function(obj){
            table.reload('testReload', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态
                ,where: { //请求参数
                    field: obj.field //排序字段
                    ,order: obj.type //排序方式
                }
            });
        });
    });
    //获取serialize数据转对象
    $.fn.parseForm=function(){
        var serializeObj={};
        var array=this.serializeArray();
        var str=this.serialize();
        $(array).each(function(){
            if(serializeObj[this.name]){
                if($.isArray(serializeObj[this.name])){
                    serializeObj[this.name].push(this.value);
                }else{
                    serializeObj[this.name]=[serializeObj[this.name],this.value];
                }
            }else{
                serializeObj[this.name]=this.value;
            }
        });
        return serializeObj;
    }
</script>
